package com.heima.wemedia.controller;

import com.heima.model.admin.dto.ChannelDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.entity.WmChannel;
import com.heima.model.wemedia.entity.WmSensitive;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

///api/v1/channel/channels 查询频道列表
//get ResponseResult  ：
@RestController
@RequestMapping(path = "/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 查询所有频道
     * @return
     */
    @GetMapping(path = "/channels")
    public ResponseResult queryAll(){
        return wmChannelService.queryAll();
    }

    /**
     * 查询频道列表
     * @return
     */
    @PostMapping(path = "/list")
    public ResponseResult list(@RequestBody ChannelDto dto){
        return wmChannelService.queryAllLimit(dto);
    }

    /**
     * 更新频道列表
     * @return
     */
    @PostMapping(path = "/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel){
        return ResponseResult.okResult(wmChannelService.update(wmChannel));
    }


    /**
     * 删除频道列表
     * @return
     */
    @GetMapping(path = "/del/{id}")
    public ResponseResult del(@PathVariable Long id){
        return ResponseResult.okResult(wmChannelService.deleteById(id));
    }

    /**
     * 新增频道
     * @return
     */
    @PostMapping(path = "/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){
        wmChannel.setIsDefault(1);
        wmChannel.setCreatedTime(new Date());
        return ResponseResult.okResult(wmChannelService.insert(wmChannel));
    }
}